package com.class05.controller;

import com.class05.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/8 9:15
 */
@Controller
@RequestMapping("user")
public class UserController {
    @GetMapping
    @ResponseBody
    public List<User> page(@RequestParam(
            required = false, defaultValue = "1") int page,
                           @RequestParam(
                                   required = false, defaultValue = "2")
                           int size) {
        System.out.println("page = " + page + ", size = " + size);
        List<User> list = new ArrayList<>();
        list.add(new User(1,"zhangsan",12));
        list.add(new User(2,"lisi",12));
        list.add(new User(3,"wangwu",12));
        list.add(new User(4,"zhaoliu",12));
        return list;

    }

    @PostMapping
    public User save(@RequestBody User user) {
        return user;
    }

    @GetMapping("{id}")
    public User detail(@PathVariable Integer id) {
        System.out.println("id = " + id);
        return null;
    }

    @PutMapping
    @ResponseBody
    public User update(@RequestBody User user) {
        return user;
    }


    @DeleteMapping("{id}")
    public User delete(@PathVariable Integer id) {
        System.out.println("id = " + id);
        return null;
    }

    @GetMapping("search")
    public List<User> search(
            String keywork,
            @RequestParam(
                    required = false, defaultValue = "1") int page,
            @RequestParam(
                    required = false, defaultValue = "10") int size
    ) {
        return null;
    }

}
